package com.tianqu.tms.www.car.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.Registry;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.www.car.actionform.CarPrivilegedCarDetailActionForm;
import com.tianqu.tms.www.car.viewhelper.CarPrivilegedCarManageViewHelper;

/**
 * 特权车管理 - 信息录入
 * @author zhao-qc
 *
 */
public class CarPrivilegedCarDetailAction extends TmsAction {

	private Logger logger = Logger.getLogger(CarPrivilegedCarDetailAction.class);
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		
		CarPrivilegedCarManageViewHelper priviCarViewHelper = new CarPrivilegedCarManageViewHelper();
		String lPlate = Registry.getConfig(TmsConstants.TMS_DEFLICENSEPLATE_KEY);//车牌前两位
		
		CarPrivilegedCarDetailActionForm actionFromFM = (CarPrivilegedCarDetailActionForm)uc.getInputForm();
		if("1".equals(actionFromFM.getFlg())){
			priviCarViewHelper.setLicensePlate(actionFromFM.getLicensePlate());
			priviCarViewHelper.setTempLicensePlate(actionFromFM.getTempLicensePlate());
			priviCarViewHelper.setEndDate(actionFromFM.getEndDate());
			priviCarViewHelper.setRemarks(actionFromFM.getRemarks());
		}else{
			priviCarViewHelper.setLicensePlate(lPlate);
		}
		
		uc.setAttribute(TmsConstants.VIEWHELP, priviCarViewHelper);
		request.setAttribute(VIEWHELP, priviCarViewHelper);
		
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
